const CACHE_EXPIRE_TIME=parseInt(import.meta.env.VITE_PAGE_CACHE_EXPIRE)
const state=() => ({ 
  caches:[]
})
const mutations={
  addCachePage(state,data){
    state.caches.push(data)
  },
  removeExpireCache(state){
    const time=(new Date()).getTime()
    state.caches=state.caches.filter(item => time-item.time<CACHE_EXPIRE_TIME)
  },
  clearCache(state){
    state.caches=[]
  }
}
const actions={ 

}
const getters={ 
  hasCachePage(state){
    return (name) => state.caches.findIndex(item => item.name==name)==-1?false:true
  },
  getCachePages(state){
    return state.caches.map(item => item.name)
  }
}
const namespaced=true
export {
  state,mutations,actions,getters,namespaced
}